import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect:"/index",
    component: ()=>import("../views/baseLayout"),
    children:[{
      path:"/index",
      component:()=>import("../views/index")
    },
    {
      path:"/service",
      component:()=>import("../views/service")
    },
    {
      path:"/my",
      component:()=>import("../views/my")
    }]
  },
  {
    path: "/item/:id",
    component:()=>import("../views/item")
  }
  ,
  {
    path: "/change",
    component:()=>import("../views/change")
  }
  ,
  {
    path: "/game",
    component:()=>import("../views/game")
  } ,
  {
    path: "/code",
    component:()=>import("../views/code")
  },
  {
    path: "/search",
    component:()=>import("../views/search")
  },
  {
    path: "/login",
    component:()=>import("../views/login")
  }

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next)=>{
  var qq = window.localStorage.getItem("qq")
 if(to.path=='/login')
  return  next()
  else  if(qq!=null&&qq!=undefined&&qq.length>4){
    next()
  }
  else{
    next('/login')
  }

})

export default router
